import Mock from "mockjs"
const Random = Mock.Random

/*
统一的返回数据
 */
const Result = {
  code: 200,
  msg: '操作成功',
  data: ''
}
//Mock.setup({ timeout: 3000 });

const loginInfo= Mock.mock({
  "id|1-100": 100,
   username: Random.cname()
})

Mock.mock('/user/login', 'post', (res)=>{
  console.log(res)
  Result.data = loginInfo
  return Result
})

Mock.mock( "/user/update", 'post', (res) => {
  console.log(res);
  Result.data = "success";
  return Result;
})

Mock.mock( "/user/info", 'get', () => {
  Result.data = loginInfo;
  return Result;
})

Mock.mock('/user/register/verify', 'post', (res) => {
  console.log(res)
  Result.data = 'success'
  return Result
})

Mock.mock(/\/user\/register\/getCode\/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/, 'get', () => {
  Result.data = 'success'
  return Result
})


const recommendInfo = Mock.mock({
  "array|4-6": [
    {
      "bookId|1-10000": 100,
      "bookName|+1": [Random.ctitle(3, 10),Random.ctitle(3, 10),Random.ctitle(3, 10)],
      "bookPicture|+1": [
        "https://bpic.588ku.com/back_origin_min_pic/19/10/22/380abc8c5a7355574279311b90c3da9d.jpg",
        "https://img0.baidu.com/it/u=3144625417,3693378732&fm=253&fmt=auto&app=120&f=JPEG?w=650&h=488",
        "https://img0.baidu.com/it/u=1673316911,2265347774&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500"
      ]
    }
  ]
})
Mock.mock(/\/book\/recommend\/small|big/, 'get', () => {
  Result.data = recommendInfo.array;
  return Result
})


const bookDetailInfo = Mock.mock({
  "bookId|1-10000": 100,
  bookName: Random.ctitle(3, 10),
  author: Random.cname(),
  "price|1-100.1-2": 1,
  "score|0-4.0-1": 1,
  bookDesc: Random.cparagraph(50),
  authorDesc: Random.cparagraph(50),
  evaluate: Random.cparagraph(50),
  bookPicture: "https://img1.baidu.com/it/u=612434286,1700671532&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1677517200&t=baae1fa4ddbf2480024939bc42a6fb2c"
})
Mock.mock(/\/book\/detail\/\d+/, 'get', () => {
  Result.data = bookDetailInfo;
  return Result;
})


const sellWellBookInfo = Mock.mock({
  "array|10-20": [
    {
      "bookId|1-10000": 100,
      "bookName|+1": [Random.ctitle(3, 10),Random.ctitle(3, 10),Random.ctitle(3, 10)],
      "bookPicture|+1": [
        "https://img1.baidu.com/it/u=3459367960,1947595692&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
        "https://img1.baidu.com/it/u=3927551765,1886597288&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=700",
        "https://img0.baidu.com/it/u=1413551014,1065263742&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=654",
        "https://img1.baidu.com/it/u=1318431161,540976241&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
      ],
      "price|1-100.1-2": 1,
      "score|0-4.0-1": 1,
      "author|+1": [Random.cname(),Random.cname(),Random.cname()]
    }
  ]
})
Mock.mock('/book/well', 'get', () => {
  Result.data = sellWellBookInfo.array;
  return Result
})

Mock.mock('/type/first', 'get', () => {
  Result.data = [
    {
      "typeId": 1,
      "typeName": "小说"
    },
    {
      "typeId": 2,
      "typeName": "儿童读物"
    },
    {
      "typeId": 3,
      "typeName": "工具书"
    },
    {
      "typeId": 4,
      "typeName": "手册"
    }
  ]
  return Result
})


const newByTypeBookInfo = Mock.mock({
  "array|100": [
    {
      "array|10-20": [
        {
          "bookId|1-10000": 100,
          "bookName|+1": [Random.ctitle(3, 10),Random.ctitle(3, 10),Random.ctitle(3, 10)],
          "bookPicture|+1": [
            "https://img0.baidu.com/it/u=3141640400,77183684&fm=253&fmt=auto&app=120&f=JPEG?w=640&h=862",
            "https://img0.baidu.com/it/u=839182131,2615451634&fm=253&fmt=auto&app=138&f=JPEG?w=350&h=350",
            "https://img2.baidu.com/it/u=1691395216,2958437779&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=700",
            "https://img0.baidu.com/it/u=954356176,1165500544&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
          ],
          "price|1-100.1-2": 1,
          "score|0-4.0-1": 1,
          "author|+1": [Random.cname(),Random.cname(),Random.cname()]
        }
      ]
    }
  ]
})
Mock.mock(/\/book\/type\/first\/\d+/, 'get', () => {
  Result.data = newByTypeBookInfo.array[Random.integer(0, 99)].array;
  return Result
})


Mock.mock('/type/second', 'get', () => {
  Result.data = [
    {
      typeId: 11,
      typeName: "科技类"
    },
    {
      typeId: 22,
      typeName: "Java类"
    },
    {
      typeId: 33,
      typeName: "算法类"
    },
    {
      typeId: 44,
      typeName: "漫画类"
    },
    {
      typeId: 55,
      typeName: "地理类"
    }
  ]
  return Result
})

Mock.mock('/book/price/bet', 'get', () => {
  Result.data = {
    min: Random.integer( 10, 30),
    max: Random.integer( 70, 100)
  }
  return Result
})


Mock.mock( /\/book\/condition\/\d+\/\d+\/\d+/, 'get', () => {
  Result.data = newByTypeBookInfo.array[Random.integer(0, 99)].array;
  return Result
})



const picInfo = [
  "https://img2.baidu.com/it/u=260021457,2152166386&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500",
  "https://img2.baidu.com/it/u=2456396253,1213722944&fm=253&fmt=auto&app=138&f=JPG?w=560&h=320",
  "https://img1.baidu.com/it/u=4037665582,1665463600&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500",
  "https://img0.baidu.com/it/u=2110783569,3650855013&fm=253&fmt=auto&app=138&f=JPEG?w=658&h=299",
  "https://img2.baidu.com/it/u=652573327,3619363721&fm=253&fmt=auto&app=138&f=JPEG?w=1022&h=500",
  "https://img2.baidu.com/it/u=2835439759,2645923255&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500",
  "https://img2.baidu.com/it/u=3405479420,581330551&fm=253&fmt=auto&app=138&f=JPEG?w=499&h=320"
]
Mock.mock( /\/pic\/.+$/, 'get', () => {
  Result.data = picInfo[Random.integer(0, 6)];
  return Result
})


const cartBookInfo = Mock.mock({
  "array|100": [
    {
      "array|1-4": [
        {
          "cartId|1-10000": 100,
          "bookId|1-10000": 100,
          "bookName|+1": [Random.ctitle(3, 10),Random.ctitle(3, 10),Random.ctitle(3, 10)],
          "bookPicture|+1": [
            "https://img1.baidu.com/it/u=3459367960,1947595692&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
            "https://img1.baidu.com/it/u=3927551765,1886597288&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=700",
            "https://img0.baidu.com/it/u=1413551014,1065263742&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=654",
            "https://img1.baidu.com/it/u=1318431161,540976241&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
          ],
          "price|1-100.1-2": 1,
          "quantity|1-100": 1
        }
      ]
    }
  ]
})
Mock.mock( '/cart/get', 'get', () => {
  Result.data = cartBookInfo.array[Random.integer(0, 99)].array;
  return Result
})

const collectBookInfo = Mock.mock({
  "array|100": [
    {
      "array|1-4": [
        {
          "collectId|1-10000": 100,
          "bookId|1-10000": 100,
          "bookName|+1": [Random.ctitle(3, 10),Random.ctitle(3, 10),Random.ctitle(3, 10)],
          "bookPicture|+1": [
            "https://img1.baidu.com/it/u=3459367960,1947595692&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
            "https://img1.baidu.com/it/u=3927551765,1886597288&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=700",
            "https://img0.baidu.com/it/u=1413551014,1065263742&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=654",
            "https://img1.baidu.com/it/u=1318431161,540976241&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
          ],
          "bookType": "测试类",
          "collectTime": '@datetime',
        }
      ]
    }
  ]
})
Mock.mock( '/collect/list', 'get', () => {
  Result.data = collectBookInfo.array[Random.integer(0, 99)].array;
  return Result
})


Mock.mock( '/cart/del', 'post', (res) => {
  console.log(res.body);
  Result.data = "success";
  return Result;
})

Mock.mock( '/collect/del', 'post', (res) => {
  console.log(res.body);
  Result.data = "success";
  return Result;
})

Mock.mock( '/cart/update', 'post', (res) => {
  console.log("要更新的" + res.body);
  Result.data = "success";
  return Result;
})


const orderListInfo = Mock.mock({
  "array|100": [
    {
      "array|1-4": [
        {
          "orderId|1-10000": 100,
          "bookName|+1": [Random.ctitle(3, 10),Random.ctitle(3, 10),Random.ctitle(3, 10)],
          "bookPicture|+1": [
            "https://img1.baidu.com/it/u=3459367960,1947595692&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
            "https://img1.baidu.com/it/u=3927551765,1886597288&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=700",
            "https://img0.baidu.com/it/u=1413551014,1065263742&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=654",
            "https://img1.baidu.com/it/u=1318431161,540976241&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
          ],
          "price|1-100.1-2": 1,
          "quantity|1-100": 1,
          "state|+1": ["准备发货", "已发货", "已签收", "已完成"],
          "total|100-10000.1-2": 1,
        }
      ]
    }
  ]
})
Mock.mock( '/order/all', 'get', () => {
  Result.data = orderListInfo.array[Random.integer(0, 99)].array;
  return Result;
})


const borrowListInfo = Mock.mock({
  "array|100": [
    {
      "array|1-4": [
        {
          "borrowId|1-10000": 100,
          "bookName|+1": [Random.ctitle(3, 10),Random.ctitle(3, 10),Random.ctitle(3, 10)],
          "bookPicture|+1": [
            "https://img1.baidu.com/it/u=3459367960,1947595692&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
            "https://img1.baidu.com/it/u=3927551765,1886597288&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=700",
            "https://img0.baidu.com/it/u=1413551014,1065263742&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=654",
            "https://img1.baidu.com/it/u=1318431161,540976241&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
          ],
          "state|+1": ["准备发货", "已发货", "已签收", "已完成"],
          "borrowTime": '@datetime',
          "limit": '@integer(10, 30)',
          "returnTime": '@datetime',
          "remarks": "备注测试"
        }
      ]
    }
  ]
})
Mock.mock( '/borrow/list', 'get', () => {
  Result.data = borrowListInfo.array[Random.integer(0, 99)].array;
  return Result;
})

const borrowDetailInfo = Mock.mock({
  "array|4": [
    {
      "borrowId|1-10000": 100,
      "bookName|+1": [Random.ctitle(3, 10),Random.ctitle(3, 10),Random.ctitle(3, 10)],
      "author|+1": [Random.cname(),Random.cname(),Random.cname()],
      "bookPicture|+1": [
        "https://img1.baidu.com/it/u=3459367960,1947595692&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
        "https://img1.baidu.com/it/u=3927551765,1886597288&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=700",
        "https://img0.baidu.com/it/u=1413551014,1065263742&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=654",
        "https://img1.baidu.com/it/u=1318431161,540976241&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
      ],
      "summary": '@cparagraph',
      "publisher": '@cname',
      "createdAt": '@datetime',
      "delay|+1": [0,1],
      "state|+1": [1,2,3],
      "returnAt": '@datetime'
    }
  ]
})
Mock.mock( /\/borrow\/detail\/\d+/, 'get', () => {
  //console.log(orderDetailInfo.array[Random.integer(0, 3)]);
  Result.data = borrowDetailInfo.array[Random.integer(0, 3)];
  return Result;
})

Mock.mock( /\/order\/confirm\/\d+/, 'post', () => {
  Result.data = "success";
  return Result;
})


export default Mock



